package com.xbhog.screwdemo.值对象;

public enum OrderStatusVO {
    PLACED(0, "下单"),
    PAID(1, "支付"),
    COMPLETED(2, "完成"),
    CANCELLED(3, "退单");

    private final int code;
    private final String description;

    OrderStatusVO(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    //根据code获取对应的OrderStatus
    public static OrderStatusVO fromCode(int code) {
        for (OrderStatusVO status : OrderStatusVO.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid code for OrderStatus:" + code);
    }
}
